package com.example.tests;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;

import junit.framework.Assert;
import static org.hamcrest.Matchers.*;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class GroupCreationTest extends TestBase {

	Random rnd = new Random();
		
	@DataProvider(name ="randomGroups")
	public Iterator<Object[]> generateRandomGroups() {
		List<Object[]> list = new ArrayList<Object[]>();
		for (int i = 0; i < 5; i++) {
			GroupObject group = new GroupObject()
			.setName1("name"+rnd.nextInt())
			.setHeader("header"+rnd.nextInt())
			.setFooter("footer"+rnd.nextInt());
			list.add(new Object[]{group});
		}
		return list.iterator();
		 
	}
	
	@Test (dataProvider = "randomGroups")
	public void validGroupCanBeCraetedTest(GroupObject validDataGroup) throws Exception {
		Set<GroupObject> oldList = app.getGroupHelper().getGroups();
		// action
		app.getGroupHelper().creationGroup(validDataGroup);
		// verification
		Set<GroupObject> newList = app.getGroupHelper().getGroups();
		verifyGroupAdded(oldList, validDataGroup, newList);
		Assert.assertEquals(newList.size(), oldList.size()+1);
		oldList.add(validDataGroup);
//		Assert.assertEquals(newList, oldList);
	}
	
//	@Test
	public void testGroupWithEmptyDataCanBeCreated() throws Exception {
		GroupObject emptyDataGroup = new GroupObject().setName1("")
				.setHeader("").setFooter(""); 
		app.getGroupHelper().creationGroup(emptyDataGroup);
	}

	private void verifyGroupAdded(Set<GroupObject> oldList,
			GroupObject validDataGroup, Set<GroupObject> newList) {
//		Assert.assertEquals(newList.size(), oldList.size()+1);
		

		
	}

}
